/*----------------------------------------------
| noka tree v1.0 www.97521.com                 |
| rebin 2014-01-10                             |
|---------------------------------------------*/
var ntreetran = Class.create({
    version: '1.0',
    //=================初始化方法===============================
    initialize : function(cfg) {
    	this.cfg = cfg;					//配置信息
    	this.rnodeid=-1;
    	this.isSelect=false;//是否为下拉选项
    	this.bdy = $(cfg.id+'_bdiv');
    	this.readonly=('readonly'==cfg.readonly);
    	this.disabled = ('disabled'==cfg.disabled);
    	this.allownull = cfg.allownull;
    	this.hImg;
    	this.mImg;
    	this.slang = cfg.slang;
    	this.lower = cfg.lower;
    	this.bwidth = (undefined !=cfg.bwidth?cfg.bwidth:300);
    	this.width = (undefined !=cfg.width?cfg.width:120);
    	this.movextop = 0;
    	this.titllev = (undefined!=cfg.titllev?cfg.titllev:0);//名称级别
    	this.updServerFunction = cfg.ServerFunction;//修改时调用的服务器方法
    	this.ispid = cfg.spid;
    	this.value = cfg.value;
    	this.autohide = (undefined!=cfg.autohide?cfg.autohide:5);//默认为5秒
    	this.checktype = (undefined!=cfg.checktype?cfg.checktype:false);//名称级别;//是否为多选
    	this.onclear = cfg.onclear;//在清除时调用方法
    	this.onclose = cfg.onclose;//在关闭选项调用
    	this.onchange = cfg.onchange;//在值改变时调用
    	this.height = 0;
    	this.dataurl = (undefined == cfg.dataurl?cfg.rurl+'/nokatag/ntree'+cfg.id+'.tre':cfg.dataurl);
    },
    //=================初始化选择界面==========================
    initSelectBody : function(){
    	var idx = 0;
        var html = [];
        var self = this;
        var rid = self.cfg.id;
        var tre=$(self.cfg.id+'_tdiv');
        //-------------------选项卡标题------------------------
        html[idx++] = '<div id="'+rid+'_select_tab_id">';
        html[idx++] = '<div id="'+rid+'_select_tab_title">';//选项卡标题
        html[idx++] = '</div>';
        html[idx++] = '<div style="float: right;" id="'+rid+'_title_close" class="titl_close">'+self.cfg.sclose+'</div>';
        html[idx++] = '<div style="float: right;" id="'+rid+'_title_clear" class="titl_clear">'+self.cfg.sclear+'</div>';
        html[idx++] = '<div  style="clear: both;" class="line"></div>';
        html[idx++] = '</div>';
        //------------nodes------------------------------
        html[idx++] = '<div id="'+rid+'_select_body_id">';//选项卡内容
        html[idx++] = '</div>';
        tre.innerHTML=html.join('');
        $(rid+'_title_close').observe('click',function(a){
        	var isgon = true;
        	if(undefined !=self.onclose){
        		try{
        			var par = {obj:$(self.cfg.id),value:$(self.cfg.id).value,svalue:$(self.cfg.id+'_sinput').value};
        			isgon = self.onclose(par);
        		}catch(e){}
        	}
        	if(undefined==isgon || isgon){
        		$(self.cfg.id+'_tdiv').hide();
        	}
    	});
        $(rid+'_title_clear').observe('click',function(event){
        	//-------------调用外部onchange方法------------------------------------------------------------------------------------
        	var isgon = self.userClear();
        	//----------------------------------------------------------------------------------------------------------------
        	if(undefined==isgon || isgon){
        		$(self.cfg.id).value='';
        		$(self.cfg.id+'_sinput').value='';
        	}
    	});
    },
    //---------------选种标题--------------------------------------------------------------------------------------------------------
    selectTab : function(node){
    	var self = this;
    	var rid = self.cfg.id;
    	$$('a[id^="'+rid+'_nktitle_"]').each(function(alink,index) {
    		alink.removeClassName('title');
    		alink.addClassName('notitle');
    	});
    	$$('div[id^="'+rid+'_select_body_id_"]').each(function(alink,index) {
    		alink.hide();
    	});
    	var sobj = $(rid+'_nktitle_'+node.pid);
    	sobj.removeClassName('notitle');
    	sobj.addClassName('title');
    	try{
    		var sbody = $(rid+'_select_body_id_'+node.pid);
    		sbody.show();
    	}catch(e){}
    },
    //---------------获取长名称------------------------------------------------------------------------------------------------------
    getLongTitle : function(nodeid,lve,sep){//节点id,深度
    	var self = this;
    	var nodes = self.getParentNode(nodeid);
    	var title ='';
    	var max = ((undefined!=lve && lve>-1 && lve<nodes.length)?lve:nodes.length-1);
    	var sepf = (undefined!=sep?sep:'-');
    	if(nodes.length>0){
    		for(var i=max;i>-1;i--){
    			if(i>0){
    				title+=nodes[i].name+sepf;
    			}else{
    				title+=nodes[i].name;
    			}
    		}
    	}
    	return title;
    },
   //------------------获取父亲节点---------------------------------------------------
    getParentNode : function(nodeid){
    	var self = this;
    	self.parentNodes=[];
    	var pnodes = [];
    	try{
    		pnodes = self.getParentNodes(nodeid);
    	}catch(e){}
    	return pnodes;
    },
    getParentNodes : function(nodeid){
    	var self = this;
    	var rid = self.cfg.id;
    	var node =  self.getNode(nodeid);//当前节点
    	self.parentNodes[self.parentNodes.length]=node;
    	if(undefined !=node){
	    	$$('div[class~="'+rid+'_nodes"]').each(function(row,index) {
	    		var pnode = row.innerHTML.evalJSON();
	    		if(pnode.id==node.pid){
	    			self.getParentNodes(pnode.id);
	    		}
	    	});
    	}
    	return self.parentNodes;
    },
    //------------获取节点对象-----------------------------------------------------
    getNodes : function(nodeids){
    	var self = this;
    	var nodes = [];
    	var idx = 0;
    	var ids = nodeids.split(',');
    	for(var i=0;i<ids.length;i++){
    		nodes[idx++]=self.getNode(ids[i]);
    	}
    	return nodes;
    },
    //--------------------获取节点信息------------------------------------------
    getNode : function(nodeid){
    	var self = this;
    	var rid = self.cfg.id;
    	var node = $(rid+'_'+nodeid+'_json');
    	if(undefined != node){
    		try{
    			return node.innerHTML.evalJSON();
    		}catch(e){}
    	}
    	return node;
    },
    //---------------插入标题--------------------------------------------------------------------------------------------------------
    insertTitle : function(nodes){
    	var idx = 0;
        var html = [];
        var self = this;
        var rid = self.cfg.id;
        var sbody = $(rid+'_select_tab_title');
    	html[idx++] = '<div id="'+rid+'_select_divid_'+nodes[0].pid+'" class="title_div"><a class="title" id="'+rid+'_nktitle_'+nodes[0].pid+'">'+self.slang+'</a>';
    	html[idx++] = '<div style="display: none;">';
      	html[idx++] = '<div id="'+rid+'_'+nodes[0].level+'">'+self.CustomToJson(nodes[0])+'</div>';
      	html[idx++] = '<div id="'+rid+'_nktitle_'+nodes[0].pid+'_json">'+self.CustomToJson(nodes[0])+'</div>';
      	html[idx++] = '</div>';
    	html[idx++] = '</div>';
    	sbody.insert(html.join(''));
    },
    //-------------获取总宽度--------------------------------------------------------------------------------------------------------
    getBodyWidth : function(){
    	var self = this;
    	var rid = self.cfg.id;
    	var width = 60;
    	var swidth = self.width+18;
    	$$('div[id^="'+rid+'_select_divid_"]').each(function(alink,index) {
    		width+=$(alink).getWidth()+5;
		});
    	$$('div[id^="'+rid+'_select_body_id_"]').each(function(alink,index) {
    		if(self.height<$(alink).getHeight()){
    			self.height = $(alink).getHeight();
    		}
    	});
    	width=(width<self.bwidth?self.bwidth:width);
    	width=(width<swidth?swidth:width);
    	self.height=(self.height<40?40:self.height);
    	return {width:width,height:self.height};
    },
    //---------------插入body------------------------------------------------------------------------------------------------------
    insertBodyNode : function(nodes){
    	var idx = 0;
        var html = [];
        var self = this;
        var rid = self.cfg.id;
        var sbody = $(rid+'_select_body_id');
    	//----------插入节点-----------------------------------------------------------------------------------------------------------
        html[idx++] = '<div id="'+rid+'_select_body_id_'+nodes[0].pid+'" style="width:'+self.bwidth+'px;float: left;">';
        for(var i=0;i<nodes.length;i++){
       	 var rnod = nodes[i];
       	 html[idx++] = '<a id="'+rid+"_"+rnod.id+'_na" class="node" href="'+rnod.url+'"  title="'+rnod.title+'"  alt="'+rnod.title+'" target="'+rnod.target+'">';
       	 if(self.checktype){//多选
			html[idx++] = '<input  style="vertical-align:middle;" id="'+rid+"_"+rnod.id+'_checkbox" type="checkbox" name="'+rid+"_"+rnod.id+'_checkbox" value="'+rnod.id+'">';
       	 }
       	 html[idx++] =rnod.name+'</a>';
       	 html[idx++] = self.CustomAttribute(rnod);//node json
       	 html[idx++] = '<div style="display: none;">';
       	 html[idx++] = '<div id="'+rid+'_'+rnod.level+'">'+self.CustomToJson(rnod)+'</div>';
  		 html[idx++] = '</div>';
        }
        html[idx++] = '</div>';
        //----------------------------------------------------------------------------------------------------------------------------
        sbody.insert(html.join(''));
        //----------------------------------------------------------------------------------------------------------------------
        self.resetBodySize();
    },
    resetBodySize : function(){
    	var self = this;
    	var osize = self.getBodyWidth();
    	var rid = self.cfg.id;
     	$(rid+'_tdiv').setStyle({width:osize.width+'px'});
//     	$$('div[id^="'+rid+'_select_body_id_"]').each(function(alink,index) {
//     		$(alink).setStyle({width:osize.width+'px',height:osize.height+'px'});
// 		});
    },
    //--------------------------外部方法-----------------------------------------------------------------------------------------
    userChange : function(nvalue){
    	var self = this;
    	var isgon = true;//是否继续执行
    	var par = {};
    	//-------------参数-------------------------------------------------------------------------------------------------
    	try{
    		par = {obj:$(self.cfg.id),value:$(self.cfg.id).value,nvalue:nvalue};
    	}catch(e){}
    	//-------------调用外部onchange方法------------------------------------------------------------------------------------
    	if(undefined !=self.onchange){
    		try{isgon = self.onchange(par);}catch(e){}
    	}
    	return isgon;//是否继续执行
    },
    //-----------------清空数据调用外部方法--------------------------------------------------------------------
    userClear : function(){
    	var self = this;
    	var par = {};
    	var isgon = true;
    	//-------------参数-------------------------------------------------------------------------------------------------
    	try{
    		par = {obj:$(self.cfg.id),value:$(self.cfg.id).value,nvalue:''};
    	}catch(e){}
    	if(undefined !=self.onclear){//只有值为空时才调用
    		try{isgon = self.onclear(par);}catch(e){}
    	}
    	return isgon;
    },
    //---------------删除选项卡----------------------------------------------------------------------------------------------------
    removeNode : function(node){
    	var self = this;
        var rid = self.cfg.id;
        $(rid+'_select_divid_'+node.pid).remove();
        $(rid+'_select_body_id_'+node.pid).remove();
    },
    removeSubNodes : function(node){
    	var self = this;
    	var rid = self.cfg.id;
        $$('div[id^="'+rid+'_'+node.leve+'_"]').each(function(alink,index) {
        	try{
        		var nodep = alink.innerHTML.evalJSON();
        		self.removeNode(nodep);
        	}catch(e){}
    	});
    },
    //---------------插入节点数据-----------------------------------------------------------------------------------------------------
    insertNodes : function(nodes){
        var self = this;
        //----------插入标题-----------------------------------------------------------------------------------------------------------
        if(undefined == nodes || nodes.length<1){
        	return;
        }
        self.insertTitle(nodes);//插入标题
        self.insertBodyNode(nodes);//插入body节点
        self.selectTab(nodes[0]);//选中当前节点
        self.EventClick(nodes);
    },
    //--------------获取节点id------------------------------
    getNodeId : function(body,nc){
    	var self = this;
    	var rid = self.cfg.id;
    	var dnpid = body.id.substring(0,(body.id.length-nc.length));
    	var spid  = dnpid.substring(rid.length+1,dnpid.length);
    	return spid;
    },
    //--------------加载点击事件------------------------------
    EventClick : function(nodes){
    	var self = this;
    	var rid = self.cfg.id;
    	if(undefined==nodes || nodes.length<1){
    		return;
    	}
    	//---------选项卡点击事件------------------------------
    	$(rid+'_nktitle_'+nodes[0].pid).observe('click',function(a){
    		self.selectTab(nodes[0]);
    		try{
    			var titnode =$(this.id+'_json').innerHTML.evalJSON();
    			self.cfg.nodeonclick($(self.cfg.id),titnode);//外部事件
    		}catch(e){}
    	});
    	//---------节点点击事件-------------------------------
    	for(var i=0;i<nodes.length;i++){
          	 var rnod = nodes[i];
          	 $(rid+"_"+rnod.id+'_na').observe('click',function(a){
          		 try{
          			var spid = self.getNodeId(this,'_na');
          			var node = $(rid+'_'+spid+'_json').innerHTML.evalJSON();
          			var titnode =$(rid+'_nktitle_'+node.pid+'_json').innerHTML.evalJSON();
          			self.removeSubNodes(titnode);//删除以前的旧节点
          			self.ajaxLoadData(spid, '1', true, 0);//加载子节点数据
          		 	var titlobj = $(rid+'_nktitle_'+nodes[0].pid);
          		 	titlobj.innerHTML=node.name;//修改选项卡标题
          		 	if(!self.checktype){//单选时点击标题设置值
          		 		self.treeTitleClick(node);//设置选项值
          		 	}
          		 	self.cfg.titleonclick($(self.cfg.id),node);//外部事件
          		 }catch(e){}
          	 });
    	}
    	//---------节点点选框击事件-------------------------------
    	if(self.checktype){//单选时点击标题设置值
	    	for(var i=0;i<nodes.length;i++){
	          	 var rnod = nodes[i];
	          	 $(rid+"_"+rnod.id+'_checkbox').observe('click',function(event){
	          		 try{
	          			//----------阻止事件传递-----------------------------------
	          			var e=(event)?event:window.event;
	        			if (window.event) {
	        			   e.cancelBubble=true;
	        			} else {
	        			   e.stopPropagation();
	        			}
	        			//-----------------------------------------------------
	          			var spid = self.getNodeId(this,'_checkbox');
	          			var node = $(rid+'_'+spid+'_json').innerHTML.evalJSON();
	          		 	self.treeTitleClick(node,this.checked);//设置选项值
	          		 	self.cfg.titleonclick($(self.cfg.id),node);//外部事件
	          		 	self.cfg.checkboxonclick($(self.cfg.id),node);//外部事件
	          		 }catch(e){}
	          	 });
	    	}
    	}
    },
    //------------------------多个选项值------------------------------------------
    checkValue : function(v,checked){
    	var self = this;
    	var rid = self.cfg.id;
    	var cstr=(''==$(rid).value?',':','+$(rid).value+',');//1,2,13,3,32->,1,2,13,3,32,
		if(checked){
			if(cstr.indexOf(','+v+',')==-1){
				cstr+=v+',';
			}
		}else{
			var vc=','+v+',';
			cstr=cstr.replace(vc, ',');
		}
		var nvalue = (','==cstr?'':cstr.substring(1,cstr.length-1));
		var isgon = self.userChange(nvalue);//原值,新值
		if(undefined==isgon || isgon){
			$(rid).value=nvalue;
		}
    },
    //---------------------多个选项显示值---------------------------------------------
    checkSValue : function(v,checked){
    	var self = this;
    	var rid = self.cfg.id+'_sinput';
    	var cstr=(''==$(rid).value?',':','+$(rid).value+',');//1,2,13,3,32->,1,2,13,3,32,
		if(checked){
			if(cstr.indexOf(','+v+',')==-1){
				cstr+=v+',';
			}
		}else{
			var vc=','+v+',';
			cstr=cstr.replace(vc, ',');
		}
		$(rid).value=(','==cstr?'':cstr.substring(1,cstr.length-1));
    },
    //--------------加载数据---------------------------------
    ajaxLoadData : function(spid,d,endnode,load){
    	var self = this;
    	var rid = self.cfg.id;
    	var level='';
    	var idx = 0;//
    	var parsv=[];
    	self.isLoadEnd+=1;//加载级数加1
    	try{
    		if('3'==d)
    			level=$(rid+'_'+spid+'_le').value;
    		else if('4'==d)
    			level=$(rid).value;
    	}catch(e){}
    	parsv[idx++]='do='+d;//1为root节点,2为子节点 3为取下关联节点
    	parsv[idx++]=(''==spid?'':'&pid='+spid);//上级节点id,取下级关联节点时，该参数为本级节点id
    	if('3'==d)
    		parsv[idx++]=(''==level?'':'&le='+level+'_'+$(rid+'_'+spid+'_id').value);//上级节点id,取下级关联节点时，该参数为本级节点id
    	else
    		parsv[idx++]=(''==level?'':'&le='+level);//上级节点id,取下级关联节点时，该参数为本级节点id
    	parsv[idx++]='&sql='+self.cfg.sql;//sql查询语句
    	parsv[idx++]=(''==self.cfg.url?'':'&url='+self.cfg.url);//节点的url地址
    	parsv[idx++]=(''==self.cfg.target?'':'&tar='+self.cfg.target);//节点连接目标
    	parsv[idx++]=(''==self.cfg.formatcell?'':'&fc='+self.cfg.formatcell);//格式化列
    	parsv[idx++]=(''==self.cfg.pramevar?'':'&pr='+self.cfg.pramevar);//url参数
    	parsv[idx++]=('&titllev='+self.titllev);//深度
    	parsv[idx++]=(''==self.ispid?'':'&spid='+self.ispid);//spid
    	new Ajax.Request(self.dataurl, {
    		method:'post',
            parameters: parsv.join(''),
            onSuccess: function(response) {
            	var nodes = response.responseText.evalJSON();//json数据
            	//---------------节点数据--------------------------------------------------------
            	if('1'==d){//节点数据 
            		self.insertNodes(nodes);//展现子节点
            		self.rnodeid=nodes[0].pid;
            	}else if('6'==d){//获取所有父亲节点
            		self.setServerValue(nodes);
            	}
           }
    	});
    },
    //=================初始化菜单=============================
    selectShow : function(){
    	var idx = 0;
        var html = [];
        var self = this;
        var iwidth=self.cfg.width-18;
        var bodyHtml = $(self.cfg.id+'_sdiv');
        this.PreLoding();//预加载图片
        //------------配置初始化--------------------------
        html[idx++] = '<div id="'+self.cfg.id+'_sidiv" class="tree-dropdownchecklist  nk_input_lineheight nk_input_sdDiv" style="width:'+iwidth+'px;float:left;">';
        html[idx++] = '<input placeholder="'+self.cfg.placeholder+'" id="'+self.cfg.id+'_sinput" class="nk_input_lineheight nk_select_input_text" type="text" style="width:'+iwidth+'px;" readonly="readonly" '+(self.disabled?'disabled="disabled"':'')+' value="">';
        html[idx++] = '<input type="hidden" style="display:none;" value="'+self.value+'" id="'+self.cfg.id+'" name="'+self.cfg.inputname+'"/>';//记录选中的数据
        html[idx++] = '</div>';
        if(!self.allownull){
        	html[idx++] = '<div style="float:left;color: red;" class="nk_input_imgheight">*</div>';
         	html[idx++] = '<div style="float:left;"><img style="display:none;vertical-align:middle" class="nk_input_imgheight" id="'+self.cfg.id+'_img" src="'+self.cfg.rurl+'/nokatag/formcheck/images/exclamation.gif"></img></div>';
        }
        bodyHtml.innerHTML=html.join('');
        self.initSelectBody();
        //----------set value-----------------------
        if(undefined !=self.value && self.value.trim().length>0){
        	self.ajaxLoadData(self.value,'6',true,0);
        }
        //------------------------------------------
        self.ajaxLoadData(self.cfg.spid,'1',true,0);
        var obj=$(self.cfg.id+'_sidiv');
        var tre=$(self.cfg.id+'_tdiv');
        obj.observe('click',function(a){
        	if(!self.readonly && !self.disabled){
	        	var atop = obj.positionedOffset().top+obj.offsetHeight;
	    		var aleft = obj.positionedOffset().left;
	        	tre.absolutize();
	        	tre.style.top=atop;
	        	tre.style.left=aleft;
	        	tre.setStyle({left:aleft+'px',top:atop+'px'});
	        	tre.show();
	        	
        	}
        });
        obj.observe('mousemove',function(){
    		miFlg = true;
    		self.setSelectStyle(obj);
    	});
        tre.observe('mousemove',function(){
    		miFlg = true;
    		self.setSelectStyle(obj);
    	});
        
        obj.observe('mouseout',function(event){
        	miFlg = false;
        	var element = event.element();
        	if(self.autohide>0){
	        	setTimeout(function(){
	                if (element.descendantOf(self.bdy) && !miFlg){
	                	self.setNoSelectStyle(obj);
	                	tre.hide();
	                }
	            },self.autohide*1000);//5 秒以后自动关闭
        	}
        });
        tre.observe('mouseout',function(event){
        	miFlg = false;
        	var element = event.element();
        	if(self.autohide>0){
	        	setTimeout(function(){
	                if (element.descendantOf(self.bdy) && !miFlg){
	                	self.setNoSelectStyle(obj);
	                	tre.hide();
	                }
	            },self.autohide*1000);//5 秒以后自动关闭
        	}
        });
        document.observe('widget:noka_reinit',function(event){//失失焦点时验证其值
        	if(self.cfg.id.indexOf('_nkADinsert_')==-1){
     	    	var npfffs=event.memo.widgetNumber.clone();
     	    	for(var i=0;i<npfffs.length;i++){
     	    		var cfgid = Object.allclone(self.cfg);
     	    		var initem = npfffs[i];
	    			cfgid.id = initem.id;
     	    		if(cfgid.id.indexOf('_'+self.cfg.id+'_')!=-1){
     	    			(new ntreetran(cfgid)).selectShow();
     	    			try{
	    					var idx = cfgid.id.substring(cfgid.id.lastIndexOf('_')+1,cfgid.id.length);
	    					$(cfgid.id).name=$(cfgid.id).name.replace(/\[0\]/g,'['+idx+']');
	    					if(undefined!=initem.value && $(cfgid.id).name==initem.name){
	    						$(cfgid.id).setValue(initem.value);
	    					}
	    				}catch(e){}
     	    		}
     	    	}
        	}
        });
        self.initObjCht();//----------加载验证
    },
    //-------------------设置服务器的值-----------------------------------------------
    setServerValue : function(nodes){
    	var self = this;
    	var svr = '';
    	for(var i=0;i<nodes.length;i++){
    		svr+=','+nodes[i].nstr;
    	}
    	$(self.cfg.id+'_sinput').value = svr.substring(1,svr.length);
    	
    },
    //-------------------初始化事件--------------------------------------------------
    initObjCht : function(){
    	var self = this;
    	//---------------值验证-----------------------------------------------------
	    $(self.cfg.id).veri = function(){
	    	  if(($(self.cfg.id).value.trim().length<1) && !self.allownull){//不能为空
	    	    $(self.cfg.id+'_img').show();
	    	    return false;
	    	  }
	    	  try{$(self.cfg.id+'_img').hide();}catch(e){}
	    	 return true;
	    };
	    //---------------设置值-----------------------------------------------------
	    $(self.cfg.id).setValue=function(value){
			var isgon = self.userChange(value);//原值,新值
			if(undefined==isgon || isgon){
       	 		$(self.cfg.id).value=value;
       	 		self.ajaxLoadData(value,'6',true,0);
			}
	    };
	    //---------------获取值-----------------------------------------------------
	    $(self.cfg.id).getValue=function(){
       	 	return $(self.cfg.id).value;
	    };
	   //---------------获取显示值-----------------------------------------------------
	    $(self.cfg.id).getShowValue=function(){
       	 	return $(self.cfg.id+'_sinput').value;
	    };
	    //---------------隐藏选项卡--------------------------------------------------
	    $(self.cfg.id).hideSelect = function(){
	    	var obj=$(self.cfg.id+'_sidiv');
	        var tre=$(self.cfg.id+'_tdiv');
	    	self.setNoSelectStyle(obj);
        	tre.hide();
	    };
	   //----------------获取长名称-------------------------------
	   	$(self.cfg.id).getLongTitles = function(noid,lve,sep){
	   		return self.getLongTitle(noid,lve,sep); 
	   	};
	    //----------------------------------
     	$(self.cfg.id).setDisabled = function(a){
     		try{
     			$(self.cfg.id+'_sinput').writeAttribute({disabled:a});
     			self.disabled=a;
     		}catch(e){}
     	};
     	$(self.cfg.id).setReadonly = function(a){
     		try{
     			$(self.cfg.id+'_sinput').writeAttribute({readonly:a});
     			self.readonly=a;
     		}catch(e){}
     	};
    },
    //----------点击标题-----------------------
    treeTitleClick : function(node,checked){
    	var self = this;
    	if(undefined!=checked){
    		self.checkValue(node.id,checked);
    		var lotitle = node.name;
	    	try{
	    		lotitle = self.getLongTitle(node.id,self.titllev);
	    	}catch(e){}
	    	self.checkSValue(lotitle, checked);
    	}else{
    		var isgon = self.userChange(node.id);//原值,新值
			if(undefined==isgon || isgon){
	    		$(self.cfg.id).value=node.id;//设置值为id
		    	var lotitle = node.name;
		    	try{
		    		lotitle = self.getLongTitle(node.id,self.titllev);
		    	}catch(e){}
		    	$(self.cfg.id+'_sinput').value=lotitle;
			}
    	}
    	try{$(self.cfg.id+'_img').hide();}catch(e){}
    	//-----------下拉框-------------------
    	try{
    		if(self.lower!=undefined && self.lower!=''){
				$(self.lower).clearShowValue();
				$(self.lower).AjaxLoadData(node.id,-5);
			}
    	}catch(e){}
    },
   //----------选种状态-----------------------
    setSelectStyle : function(obj){
    	var self = this;
    	obj.setStyle({borderColor:'#5794bf',backgroundImage:'url('+self.hImg.src+')'});
    },
    //-----------未选种状态-------------------
    setNoSelectStyle : function(obj){
    	var self = this;
    	obj.setStyle({borderColor:'#AFAFAF',backgroundImage:'url('+self.mImg.src+')'});
    },
    //------------排序-----------------------
    systemSort : function(values){
    	var vls = values.split(',');
    	return vls.sort(function(a, b) {
    		try{
    			return parseInt(a)-parseInt(b);
    		}catch(e){}
    	});
    },
   //------------转换nodes to json---------------------------------------------------------
    CustomAttribute : function(node){
    	var self = this;
    	var idx = 0;
        var html = [];
        var nodestr = '';
        try{nodestr=Object.toJSON(node.cnode);}catch(e){}
        html[idx++] = '<div id="'+self.cfg.id+'_'+node.id+'_json" class=\"'+self.cfg.id+'_nodes\" style="display: none;">'+nodestr+'</div>';
        return html.join('');
    },
    CustomToJson : function(node){
    	var nodestr = '';
      	try{nodestr=Object.toJSON(node.cnode);}catch(e){}
      	return nodestr;
    },
    //-----------预加载图片-------------------
    PreLoding : function(){
    	var self = this;
    	self.hImg = new Image(); 
    	self.mImg = new Image();
    	self.hImg.src=self.cfg.rurl+'/nokatag/org/noka/select/dropdown_hover.png';
    	self.mImg.src=self.cfg.rurl+'/nokatag/org/noka/select/dropdown.png';
    	NBackgroundImageCache();
    }
    //====
    
});